home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10956 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.1 KB  |  52 lines

  1. Path: news.uh.edu!sukku
  2. From: sukku@menudo.uh.edu (sukumar)
  3. Newsgroups: comp.lang.c++
  4. Subject: GOTO and C++.
  5. Date: 11 Mar 1996 23:06:47 GMT
  6. Organization: University of Houston
  7. Message-ID: <4i2bm7$bmu@masala.cc.uh.edu>
  8. NNTP-Posting-Host: menudo.uh.edu
  9. X-Newsreader: TIN [version 1.2 PL2]
  10.  
  11. Hi,
  12.     Are there any inherent problems with GOTO and C++. In my application,
  13. I using GOTO and  it crashes. If I remove the goto and replace it with a flag,
  14. everyting works fine. This is how the code looks:
  15.  
  16. f()
  17. {
  18.  
  19.     char** n = NULL;
  20.  
  21.     n = new char*[20];
  22.     for(i=0; i<20; i++)
  23.     n[i] = new char[10];
  24.  
  25.     ...trivial error checking
  26.  
  27.     if(error)
  28.     goto CLEANUP;
  29.  
  30.  
  31.     ...
  32.     I use come RWCStrings (String class)  here 
  33.     ...
  34.  
  35. CLEANUP:
  36.     for(i=0; i<20; i++)
  37.     delete [] n[i];
  38.  
  39.     delete [] n;
  40. }
  41.  
  42. The program crashes on delete [] n. If I remove the goto and replace it with 
  43. the code at the CLEANUP, I am fine. I was testing the case where error is True.
  44. The debugger says there is a problem in the RWCString class.
  45.  
  46. I could only conclude that goto is causing the initialization of some vars to 
  47. screw up.
  48.  
  49. I'd appreciate it if someone can throw some light on this.
  50.  
  51. -Srini.
  52.